package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.pojo.param.ArticleActionParam;
import com.tarena.lbs.content.pojo.param.ArticleContentParam;
import com.tarena.lbs.content.pojo.query.ArticleQuery;
import com.tarena.lbs.content.pojo.vo.ArticleActionPageResultVO;
import com.tarena.lbs.content.pojo.vo.ArticleVO;
import com.tarena.lbs.content.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 文章业务模块接口
 */
@Slf4j
@RestController
@Tag(name = "文章相关功能接口")
public class ArticleController {
    @Autowired
    private ArticleService articleService;


    @Operation(summary = "文章分页列表查询")
    @PostMapping("/admin/content/article/list")
    public Result<List<ArticleVO>> pageList(@RequestBody ArticleQuery articleQuery)
            throws BusinessException{
        log.info("前端-文章分页列表查询"+articleQuery);
        List<ArticleVO>articleList=articleService.select(articleQuery);
        return new Result<>(articleList);
    }


    @Operation(summary = "文章保存")
    @PostMapping("/admin/content/article/insert")
    public Result<Void> addArticle(@RequestBody ArticleContentParam param)
            throws BusinessException{
        log.info("前端-文章保存"+param);
        articleService.insertArticle(param);
        return Result.success();
    }


    @Operation(summary = "文章标签集合")
    @PostMapping("/admin/content/article/getArticleLabel")
    public Result<Set<String>> articleLabels(ArticleQuery articleQuery) throws BusinessException {
        log.info("查询文章标签集合，入参:{}",articleQuery);
        Set<String> labels = articleService.articleLabels(articleQuery);
        return new Result<>(labels);
    }


    @Operation(summary = "文章详情")
    @GetMapping("/admin/content/article/get")
    public Result<ArticleVO> articleDetail(String id)throws BusinessException{
        ArticleVO articleVO = articleService.articleDetail(id);
        return new Result<>(articleVO);
    }


    @Operation(summary = "用户行为记录")
    @PostMapping("/admin/content/article/behavior")
    public Result<List<ArticleActionPageResultVO>> articleBehavior(@RequestBody ArticleActionParam param)
            throws BusinessException{
        log.debug("用户行为记录：{}", param);
        List<ArticleActionPageResultVO> list = articleService.articleBehavior(param);
        return new Result<>(list);
    }


    @Operation(summary = "查询已经点赞 收藏 访问过的文章")
    @GetMapping("admin/content/article/getBehaviorList")
    public Result<ArticleActionPageResultVO> getBehaviorLists(ArticleQuery query)
            throws BusinessException{
        return null;
    }
    @Operation(summary = "删除用户")
    @PostMapping("admin/content/article/delete/{id}")
    public Result<Void> delete(@PathVariable Integer id)throws BusinessException{
        log.info("删除用户{}",id);
        articleService.delete(id);
        return Result.success();
    }
    @Operation(summary = "编辑用户")
    @PostMapping("admin/content/article/update/{articleName}")
    public Result<Void> update(@PathVariable String articleName)throws BusinessException{
        log.info("编辑用户{}",articleName);
        articleService.updateArticle(articleName);
        return Result.success();
    }
}
